let btn = document.querySelector('#btn')
// let BrowserWindow = require('electron').remote.BrowserWindow
const { BrowserWindow } = require('@electron/remote')

window.onload = () => {
  console.log('onload')
  btn.onclick = () => {
    console.log('xx')
    newWin = new BrowserWindow({
      width: 600,
      height: 400,
      webPreferences: {
        nodeIntegration: true,
        enableRemoteModule: true,
        contextIsolation: false,
      }
    })
    newWin.loadFile('./yellow.html')

    newWin.on('close', () => {
      newWin = null;
    })
  }
}

// 右键菜单
const remote = require('@electron/remote')
console.log('remote', remote)
const rightMenu = [
  { label: '复制' },
  { label: '粘贴' },
]
const m = remote.Menu.buildFromTemplate(rightMenu)

window.addEventListener('contextmenu', (e) => {
  // console.log('右键')
  // 阻止默认事件
  e.preventDefault()
  m.popup({
    window: remote.getCurrentWindow()
  })
})